package org.ru.mse10.cvis.web.bean.action.search;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.ru.mse10.cvis.dto.user.UserSearchDTO;
import org.ru.mse10.cvis.entity.cv.User;
import org.ru.mse10.cvis.service.UserService;
import org.ru.mse10.cvis.service.search.EntitySearcher;
import org.ru.mse10.cvis.service.search.UserSearcher;
import org.ru.mse10.cvis.web.bean.action.search.datamodel.JPADataModel;

/**
 * The Class UserSearchAction.
 */
@ViewScoped
@ManagedBean(name = "userSearchAction")
public class UserSearchAction extends
		BasesSearchAction<UserService, User, UserSearchDTO> {

	/** The service. */
	@EJB
	private UserService service;

	/**
	 * The Class UserSearchDataModel.
	 */
	private class UserSearchDataModel extends
			JPADataModel<UserService, User, UserSearchDTO> {

		/** The dto. */
		private UserSearchDTO dto;

		/** The searcher. */
		private UserSearcher searcher;

		/**
		 * Instantiates a new user search data model.
		 * 
		 * @param dto
		 *            the dto
		 */
		public UserSearchDataModel(UserSearchDTO dto) {
			this.dto = dto;
			this.searcher = new UserSearcher();
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see org.ru.mse10.cvis.web.bean.action.search.datamodel.JPADataModel#
		 * getSearcher()
		 */
		@Override
		public EntitySearcher<User, UserSearchDTO> getSearcher() {
			return searcher;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see org.ru.mse10.cvis.web.bean.action.search.datamodel.JPADataModel#
		 * getService()
		 */
		@Override
		public UserService getService() {
			return UserSearchAction.this.getService();
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see
		 * org.ru.mse10.cvis.web.bean.action.search.datamodel.JPADataModel#getDto
		 * ()
		 */
		@Override
		public UserSearchDTO getDto() {
			return dto;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see org.ru.mse10.cvis.web.bean.action.search.datamodel.JPADataModel#
		 * getEntityClass()
		 */
		@Override
		public Class<User> getEntityClass() {
			return User.class;
		}

	}

	/**
	 * Start search.
	 * 
	 * @return the string
	 */
	public String startSearch() {
		return "searchUsers";
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.ru.mse10.cvis.web.bean.action.search.BasesSearchAction#
	 * previewSearchResult()
	 */
	@Override
	public String previewSearchResult() {
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.ru.mse10.cvis.web.bean.action.search.BasesSearchAction#getService()
	 */
	@Override
	public UserService getService() {
		return service;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.ru.mse10.cvis.web.bean.action.search.BasesSearchAction#createDataModel
	 * (org.ru.mse10.cvis.dto.BaseDTO)
	 */
	@Override
	public JPADataModel<UserService, User, UserSearchDTO> createDataModel(
			UserSearchDTO dto) {
		return new UserSearchDataModel(dto);
	}

}
